package org.wang.portal.task;

import org.wang.portal.status.TaskStatus;

import java.util.Map;

public class GsDataCheckTask extends MigrationTask {
    public GsDataCheckTask(String name, Map<String, String> config) {
        super(name, config, DatabaseType.valueOf(config.get("sourceDatabaseType")), DatabaseType.valueOf(config.get("targetDatabaseType")));
    }

    @Override
    public void prepareExecuteEnv() {
    }

    @Override
    public void execute() {
        setStatus(TaskStatus.IN_PROGRESS);
        try {
            System.out.println("Executing gs_datacheck task: " + getName());
            // 调用 gs_datacheck 进行数据校验的代码
            Thread.sleep(2000); // 模拟执行时间
            setStatus(TaskStatus.COMPLETED);
        } catch (Exception e) {
            setStatus(TaskStatus.FAILED);
            e.printStackTrace();
        }
    }

    @Override
    public void pause() {
        this.status = TaskStatus.PAUSED;
    }

    @Override
    public void resume() {
        if (this.status == TaskStatus.PAUSED) {
            this.status = TaskStatus.IN_PROGRESS;
            execute();
        }
    }

    @Override
    public void stop() {
        this.status = TaskStatus.FAILED;
    }

    @Override
    public double getProgress() {
        // 模拟进度
        if (status == TaskStatus.COMPLETED) {
            return 100;
        } else if (status == TaskStatus.IN_PROGRESS) {
            return 50;
        }
        return 0;
    }
}
